//
//  IMConversationManager.h
//  MLIM
//
//  Created by molon on 15/6/30.
//  Copyright (c) 2015年 molon. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "IMConstants.h"

//下面三个一般用于通知界面更新时候
//会话基本信息更新
extern NSString * const MLIM_IMConversation_UpdateDetail_Notification;
//会话新消息加入
extern NSString * const MLIM_IMConversation_NewMessages_Notification;
//IMCM clean消息
extern NSString * const MLIM_IMConversationManager_Clean_Notification;

extern NSInteger const kMLIM_MaxBackupConvCount;
extern NSInteger const kMLIM_MaxDisplayConvCount;
extern NSInteger const kMLIM_MaxBackupMessageCount;

typedef enum{
    IMConversationSearchTypeConvId,
    IMConversationSearchTypeMemberIds,
} IMConversationSearchType;

typedef void (^IMConversationSearchCallbackBlock)(IMConversation *imConv,NSError *error);

typedef void (^IMSendMessageCallbackBlock)(IMMessage *message,BOOL succeed,NSError *error);

#define IMCM ([IMConversationManager manager])
@interface IMConversationManager : NSObject

@property (readonly, nonatomic, copy) NSString *currentClientId;

@property (nonatomic, copy) void(^sendIMMessageBlock)(IMMessage *message,IMSendMessageCallbackBlock callback);
@property (nonatomic, copy) void(^imConversationSearchBlock)(IMConversationSearchType searchType,id object,IMConversationSearchCallbackBlock callback);
@property (nonatomic, copy) void(^imMessagesBlock)(NSString *imConvId,IMMessage *beforeIMMessage,NSInteger count,IMArrayResultBlock callback);

//需要更新界面里未读数回调
@property (nonatomic, copy) void(^needUpdateIMUnreadCountSumBlock)(NSInteger imUnreadCountSum);

//点击了链接的回调
@property (nonatomic, copy) void(^didClickLinkURLBlock)(NSURL *linkURL,IMConversationViewController *conVC);

//本地推送提醒的内容，
//在程序进到后台时候的那短短刹那时间，与IM系统的连接尚未来得及关闭的时候，但是有信息到来，这时候如果客户端不做处理，对用户来说会感觉像是信息没提醒到自己。
//对每条新消息设置下本地推送通知的话就能完美解决这个问题。(此本地推送会带有userInfo @{@"isForMLIM":@(YES)}; 用来与其他的区分)
//这个block是留外界设置下推送的内容简述，最好与远程推送一致
@property (nonatomic, copy) NSString *(^alertBodyForLocalNotificationBlock)(IMUser *fromIMUser,IMMessage *imMsg);

//当前显示的会话ID
@property (nonatomic, copy) NSString *currentDisplayIMConvId;

+ (instancetype)manager;

//总的有效会话的未读数量
- (NSInteger)unreadCount;

//清空当前数据
- (void)clean;

//每次切换用户需要搞一搞
- (void)resetWithCurrentClientId:(NSString*)currentClientId;

//根据id获取会话
- (void)imConvWithIMConvId:(NSString*)convId callback:(IMConversationResultBlock)callback;

//根据成员IDs获取会话
- (void)imConvWithClientIds:(NSArray*)clientIds callback:(IMConversationResultBlock)callback;

//获取排序过的有效的会话列表
- (NSArray*)sortedValidIMConversations;

//获取会话的备份消息
- (NSArray*)cacheMessagesWithIMConvId:(NSString*)convId;

//清零未读数目
- (void)clearUnreadCountWithIMConvId:(NSString*)convId;

//添加新消息到会话
- (void)addNewIMMessages:(NSArray*)imMessages toIMConvId:(NSString*)convId;

//回复消息
- (void)replyNewIMMessage:(IMMessage*)imMessage toIMConvId:(NSString*)convId;

//重试发送消息
- (void)reSendIMMessage:(IMMessage*)imMsg;

//设置草稿消息
- (void)configureTextDraftMessageWithContent:(NSString*)content toIMConvId:(NSString*)convId;

//主动设置最后一条消息
- (void)configureLastMessage:(IMMessage*)lastMessage toIMConvId:(NSString *)convId;

//通过网络获取在某某信息ID之前的数据
- (void)webIMMessagesWithIMConvId:(NSString*)convId beforeIMMessage:(IMMessage*)imMessage count:(NSInteger)count callback:(IMArrayResultBlock)callback;

//更新或者添加会话
- (void)updateOrAddIMConversations:(NSArray*)imConvs callback:(IMBooleanResultBlock)callback;

//音频是否未听
- (BOOL)isUnhearedForAudioMessageId:(NSString*)messageId;

//标记音频已听
- (void)signHearedForAudioMessageId:(NSString*)messageId;

//备份会话消息
- (void)archiverIMMessages:(NSArray*)imMessages toIMConvId:(NSString*)imConvId callback:(IMBooleanResultBlock)callback;

//配置这些会话的详情，此方法不会刷新User缓存，只会去获取没有的User
- (void)configureDetailForIMConversations:(NSArray*)imConvs callback:(IMBooleanResultBlock)callback;

@end
